package org.bee.sender;

import org.bee.json.JsonUtils;
import org.bee.model.queue.NoticeMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

@Service
public class NoticeSender {

    private final RabbitTemplate rabbitTemplate;

    public NoticeSender(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    public void sendNoticeMessage(NoticeMessage noticeMessage) {
        String message = JsonUtils.toJson(noticeMessage);
        System.out.println("send: " + message);
        if (message != null) {
            rabbitTemplate.convertAndSend("noticeExchange", "notice", message);
        }
    }
}
